var 
http = require('http'),
fs = require('fs'),
url = require('url'),
path = require('path');



http.createServer(function (request, response) {
    console.log(request.method + ': ' + request.url);
	
	var root = path.resolve('.');
	var pathName = url.parse(request.url).pathname;
	var filePath = path.join(root,pathName);
	fs.stat(filePath,function(err,stats){
		if(!err && stats.isFile()){
			//response.writeHead(200, {'Content-Type': 'text/html'});
			response.writeHead(200);
			fs.createReadStream(filePath).pipe(response);
		}
		else{
			response.writeHead(404);
			response.end('404');
		}
	})
}).listen(8080);

// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8080/');